package com.szmg.auth.web.controller;


import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.szmg.auth.model.Company;
import com.szmg.auth.service.CompanyService;


/**
 * 包含班级列表菜单内的所有操作
 */
@Controller
public class CompanyController {
	
	
	public static int pagesize = 10;
	
	@Resource(name="companyService")
	private CompanyService companyService;
	
	
	@RequestMapping(value="/manager/auth/companys",method=RequestMethod.GET)
	public ModelAndView listCompany(String pagenum,Company company){
		ModelAndView mv=new ModelAndView();
		mv.setViewName("auth/companys");
		mv.addObject("sidebar","companys");
		int num = 1;
		if(null!=pagenum){
			num = Integer.parseInt(pagenum);
		}
		List<Company> list = companyService.listCompany((num-1)*pagesize, pagesize,company);
		mv.addObject("companyList", list);
		mv.addObject("length", list.size());
		mv.addObject("pagenum", num);
		mv.addObject("company", company);
		return mv;
	}

	
	
	@RequestMapping(value="/manager/auth/addCompany",method=RequestMethod.POST)
	public ModelAndView addcompany(Company company){
		ModelAndView mv=new ModelAndView();
		Company cls = companyService.findCompanyById(company.getId());
		if(null==cls){
			mv.setViewName("redirect:/manager/auth/companys");
			companyService.addCompany(company);
		}else{
			//mv.setViewName("redirect:/manager/editCompany");
			//companyService
		}
		return mv;
	}
	
	
	
//	@RequestMapping(value="/manager/addstudent",method=RequestMethod.POST)
//	public ModelAndView addStudent(Student student){
//		ModelAndView mv=new ModelAndView();
//		Student stu = companyService.findStudentById(student.getId());
//		if(stu==null){
//			companyService.addStudent(student);
//			companyService.updateClassStudentCount(student.getClassid());
//			mv.addObject("notice","添加学生成功");
//		}else{
//			mv.addObject("notice","已经存在编号为"+student.getId()+"的学生("+stu.getName()+")！");
//		}
//		mv.addObject("companyid",student.getClassid());
//		mv.setViewName("redirect:/manager/managerstudentpage");
//		return mv;
//	}
//	
	@RequestMapping(value="/manager/auth/deleteCompany",method=RequestMethod.GET)
	public ModelAndView deleteCompany(int companyid){
		ModelAndView mv=new ModelAndView();
		companyService.deleteCompanyById(companyid);
		mv.addObject("companyid",companyid);
		mv.addObject("notice","删除公司信息成功");
		mv.setViewName("redirect:/manager/auth/companys");
		return mv;
	}
//	
//	@RequestMapping(value="/manager/updatestudent",method=RequestMethod.POST)
//	public ModelAndView updateStudent(Student student){
//		ModelAndView mv=new ModelAndView();
//		companyService.updateStudentBy(student); 
//		mv.addObject("companyid",student.getClassid());
//		mv.addObject("notice","编辑学生信息成功");
//		mv.setViewName("redirect:/manager/managerstudentpage");
//		return mv;
//	}
	
}
